package org.skatiger.jrove.component.core;

import java.io.IOException;

import org.skatiger.jrove.JroveException;
import org.skatiger.jrove.ViewContext;
import org.skatiger.jrove.component.UIComponentBase;
import org.skatiger.jrove.util.StringUtils;

public class Set extends UIComponentBase {
    private String name;
    private Object value;

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return getPropertyValue("name", name);
    }

    public Object getValue() {
        return getPropertyValue("value", value);
    }

    public void setValue(Object value) {
        this.value = value;
    }

    @Override
    public void encodeEnd(ViewContext context) throws IOException {
        String name = getName();
        if (StringUtils.isEmpty(name)) {
            throw new JroveException("requried attribute name is null.");
        }
        context.setAttribute(getName(), getValue());
    }
}
